import cv2

# 第一行 port=5000 后面的空格不能删除，删除后拉不到流
url = "udpsrc address=0.0.0.0 port=5000 " \
      "! application/x-rtp, media=video, encoding-name=H264" \
      "! rtph264depay" \
      "! h264parse" \
      "! avdec_h264" \
      "! videoconvert" \
      "! video/x-raw,width=1280,height=720,format=BGR" \
      "! appsink drop=1"
cap = cv2.VideoCapture(url, cv2.CAP_GSTREAMER)

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret:
        cv2.imshow("Input via Gstreamer", frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

cap.release()
cv2.destroyAllWindows()